package com.ynny.UserManage.Service;

import com.ynny.UserManage.dao.UserDao;
import com.ynny.UserManage.enity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImp  implements UserService{
    @Autowired
   private UserDao userDao;
    @Override
    public int register(User user) {
        System.out.println(user);
//        if ((userDao.queryUserByName(user.getUsername())!=null)){
//            return -1;//用户存在,注册失败
//        }
        String username = user.getUsername();
        System.out.println(username);
        User user1 = userDao.queryUserByName(username);
        System.out.println(user1);
        if (user1!=null){
            return -1;
        }


        System.out.println(user);
        int i = userDao.addUser(user.getPassword(), user.getUsername(), user.getId());
        System.out.println(i);
        if (i>0){
            System.out.println("注册成功");
            return 1;
        }else {
            System.out.println("注册失败");
            return -2;//注册失败,数据添加到数据库失败
        }

    }

    @Override
    public User queryUserByName(String username) {
      return  userDao.queryUserByName(username);
    }
}
